<?php

namespace app\model\system;

use app\model\BaseModel;

/**
 *
 */
class SysNotice extends BaseModel
{

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = "sys_notice";

    public function publisher()
    {
        return $this->belongsTo(SysUser::class, "publisher_id", "id");
    }

    public function getFormArray(): array
    {
        return [
            "id" => $this->id,
            "title" => $this->title,
            "content" => $this->content,
            "type" => $this->type,
            "level" => $this->level,
            "targetType" => $this->targetType,
            "targetUserIds" => $this->targetUserIds ? explode(",", $this->targetUserIds) : null
        ];
    }

    public function toArray(array $merges = []): array
    {
        $mergeArray = $this->getFormArray() + [
            "publisherName" => $this->publisher?->username,
            "publishTime" => $this->publishTime,
            "publishStatus" => $this->publishStatus,
            "isRead" => $this->isRead,
            "createTime" => $this->createTime,
            "revokeTime" => $this->revokeTime
        ];
        return $this->merge($mergeArray, $merges);
    }
}
